<template>
	<view>
		<view class="nav-tab">
			<view 
				class="li" 
				v-for="(item, index) in tabs" 
				:key="index" 
				:class="currentTab==index?'current':''"
				@click="onTabClick(index)"
			>
				<text>{{item.name}}</text>
			</view>
		</view>
		<view class="list">
		     <view class="list-cell" v-for="(item,index) in list" :key="index">
		          <view class="cell">
					<view class="head">
						<view class="head-left">
							<image></image>
							<text>{{item.title}}</text>
						</view>
						<text class="copy" @click="copyClick(item)">复制文字</text>
					</view>
					<view class="line"></view>
					<view class="cell-content">
						<text>{{item.content}}</text>
					</view>
					<view class="tip">
						<text>#点击图片获取您的专属海报#</text>
					</view>
					<image :src="item.pic" @click="showImage(item)"></image>
					<view class="date">
						<text>{{item.add_time}}</text>
					</view>
				  </view>
		     </view>
		</view>
		
		<view class="popView" v-if="isShow">
			<image :src="selectImg"></image>
			<view class="share-btn" @click="shareClick">
				<text>预览海报长按分享</text>
			</view>
			<view class="close-btn" @click="colseClick">
				<text>x</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		JSMRequest
	} from '@/module/api'
	
	export default {
		name: "material",
		
		data() {
			return {
				tabs: [],
				currentTab: 0,
				list:[],
				isShow:false,
				selectItem:null,
				selectImg:'',
			}
		},
		
		onLoad() {
			this.getCateData()
		},
		
		methods: {
			onTabClick (index) {
				if(this.currentTab == index) return
				this.currentTab = index
				this.getPageData()
			},
			
			showImage(item) {
				this.selectItem = item
				this.getShareImage()
			},
			
			shareClick() {
				uni.previewImage({
					urls:[this.selectImg]
				})
			},
			
			getCateData () {
				let _t = this				
				JSMRequest({
					tag: "jsm-promotion-cate",
					method: "POST",
					params: {
						
					}
				}).then(({data}) => {
					_t.tabs = data
					_t.getPageData()
				}).catch(e => {
					
				})
			},
			
			getPageData(){
				let _t = this;
				JSMRequest({
					tag: "jsm-promotion-index",
					method: "POST",
					params: {
						cat_id:_t.tabs[_t.currentTab].id
					}
				}).then(({data}) => {
					_t.list = data
				}).catch(e => {
					
				})
			},
			
			getShareImage(){
				let _t = this;
				JSMRequest({
					tag: "jsm-promotion-sharePic",
					method: "POST",
					params: {
						scene:_t.tabs[_t.currentTab].id,
						promotion_id:_t.selectItem.id
					}
				}).then(({data}) => {
					_t.selectImg = data
					_t.isShow = true
				}).catch(e => {
					
				})
			},
			
			colseClick(){
				this.isShow = false;
			},
			
			//复制文字
			copyClick (item) {
				uni.setClipboardData({
					data: 'item.title',
					success: function () {
						uni.showToast({
							title:'文字已复制',
						})
					}
				})
			},
		}
	}
</script>

<style lang="less" >
page {
	background-color: #EEEEEE;
}
.nav-tab{
        width: 100%;
        position: absolute;
        height: 80px;
        top: 0;
        left: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;
		overflow-x: auto;
        z-index: 10;

        .li{
            width: 50%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;

            text{
                color: #999;
                font-size: 26px;
            }
			&.current{
// 
//                 &::after{
//                     display: block;
//                     content: '';
//                     position: absolute;
//                     bottom: 6px;
//                     left: 50%;
//                     margin-left: -14px;
//                     width: 28px;
//                     height: 6px;
//                     background: @yellow;
//                 }
//                 
                text{
                    color: red;
                }
            }
		}
}

.list {
	margin-top: 100px;
	.cell {
		padding: 20px 20px 20px 20px;
		background-color: white;
		margin-top: 20px;
		.head {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			.head-left {
				display: flex;
				flex-direction: row;
				align-items: center;
				image{
					width: 64px;
					height: 64px;
					border-radius: 32px;
				}
				text{
					margin-left: 10px;
					color: #999;
					font-size: 28px;
				}
			}
			.copy {
				font-size: 28px;
				color: red;
			}
		}
		.line {
			margin-top: 10px;
			background-color: #6E6E6E;
			height: 1;
			width: 100%;
		}
		.cell-content {
			margin-top: 10px;
			text {
				font-size: 28px;
			}
		}
		.tip {
			margin-top: 20px;
			text {
				font-size: 28px;
				color: orange;
			}
		}
		image {
			margin-top: 10px;
			width: 300px;
			height: 500px;
		}
		.date {
			margin-top: 10px;
			text {
				font-size: 28px;
				color: #999;
			}
		}
	}
}

.popView {
	display: flex;
	flex-direction: column;
	align-items: center;
	position: absolute;
	top: 0px;
	bottom: 0;
	left: 0;
	right: 0;
	background:rgba(0,0,0,0.5);
	z-index: 11;
	image {
		margin-top: 30px;
		height: 84%;
		width: 80%;
	}
	.share-btn {
		margin-top: 3.5%;
		display: flex;
		flex-direction: column;
		align-items: center;
		align-content: center;
		justify-content: center;
		width: 80%;
		height: 90px;
		background-color: red;
		border-radius: 45px;
		text {
			color: white;
			font-size: 32px;
		}
	}
	.close-btn{
		position: absolute;
		top: 20px;
		right: 10%;
		width: 50px;
		height: 30px;
		text {
			font-size: 50px;
			color: white;
		}
	}
}

</style>
